Return * for n number of times


Posted by Christy on 2022-04-19

Description: Write a function that accepts a number n and returns * for n number of times

function star(n) {

}

console.log(star(3)); // ***
function star(n) {
  let result = "";
  for (let i = 1; i <= n; i++) {
    result += "*";
  }
  return result;
}

console.log(star(3));

Be careful about the way of ouput, if it's print -> console.log; if it's return -> return










Related Posts

我要成為前端工程師的學習筆記:HTML & CSS 篇 - Box Model、區塊水平置中、文字水平調整 Day7

我要成為前端工程師的學習筆記:HTML & CSS 篇 - Box Model、區塊水平置中、文字水平調整 Day7

MTR04 W2 D18 陣列練習題

MTR04 W2 D18 陣列練習題

[Android] 非靜態內部類別可能造成記憶體洩漏

[Android] 非靜態內部類別可能造成記憶體洩漏


Comments